<template>
	<view>
		<u-card :show-head="false">
			<view class="" slot="body">
				<template v-for="article in articles">
					<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0" @click="openPage('/pages/article/detail',{id:article.id})">
						<view class="u-body-item-title u-line-2 u-flex-1">{{article.title}}</view>
						<image :src="article.cover"	mode="aspectFill"></image>
					</view>
				</template>
			</view>
		</u-card>
		<wx-share :title='pageTitle' :desc="shareDesc" :imgUrl="shop.cover" :link="currentPage" ref="wxs"></wx-share>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: location.href,
				scrollTop: 0,
				articles: [],
				user: {},
				paging: {
					current_page: 1,
					total_pages: 1,
					page_zie: 100
				},
				loadStatus: 'loadmore',
				loadText: {
					loadmore: '加载更多',
					loading: '努力加载中',
					nomore: '没有更多了'
				},
				shop:{}
			}
		},
		computed:{
			pageTitle() {
				if(this.shop.name){
					return this.shop.name+'每日分享'
				}
				return '每日分享'
			},
			shareDesc() {
				if(this.shop.order_footer_text){
					return this.shop.order_footer_text
				}
				return this.shop.store_introduction
			}
		},
		onLoad() {
			this.getShop()
		},
		onShow() {
			this.getUserInfo();
			this.getArticleList();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			if (this.paging.current_page >= this.paging.total_pages) {
				this.loadStatus = 'nomore';
				return;
			}
			this.loadStatus = 'loading';
			this.paging.current_page = ++this.paging.current_page;
			this.getArticleList();
		},
		methods: {
			getShop() {
				this.$u.post('/shopping/shop-setting', {}).then(res => {
					this.shop = res;
				}).catch(e => {

				})
			},
			getUserInfo() {
				this.$u.post('/user/info', {}).then(res => {
					this.user = res;
					if (this.user.referral_id == 0) {
						this.user.referral_id = '';
					}
				}).catch(e => {
					console.log(e)
				})
			},
			getArticleList() {
				this.$u.post('/article/list', this.paging).then(res => {
					if (res.page.current_page === 1) {
						this.articles = res.list;
					} else {
						this.articles = this.articles.concat(res.list)
					}
					this.paging.current_page = res.page.current_page;
					this.paging.total_pages = res.page.total_pages;
					this.paging.page_size = res.data.page_size;
				}).catch(e => {
					console.log(e)
				})
			},
			openPage(jumpURL, params = {}) {
				this.$u.route({
					type: 'to',
					params: params,
					url: jumpURL,
					animationType: 'slide-in-bottom'
				});
			},
			loadMore() {
				console.log('load more')
				if (this.paging.current_page < this.paging.total_pages) {
					this.paging.current_page = this.paging.current_page + 1;
					this.getArticleList();
				}
			}

		}
	}
</script>

<style scoped lang="scss">

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
</style>
